package cn.hiapi.shopkeeper.service.user;

import cn.hiapi.basic.ResUtils;
import cn.hiapi.basic.service.AbsBasicService;
import cn.hiapi.shopkeeper.entity.user.HistoryRecord;
import cn.hiapi.shopkeeper.jpa.user.HistoryRecordJpa;
import cn.hiapi.utils.TaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author AdinZ
 * @date 2022/12/31 21:55
 */
@Service
public class HistoryRecordService extends AbsBasicService<HistoryRecordJpa, HistoryRecord, Long> {

    /**
     * 添加历史记录
     *
     * @param uid
     * @param shopId
     */
    public void addRecord(long uid, long shopId) {
        TaskExecutor.getInstance().execute(() -> {
            HistoryRecord record = new HistoryRecord();
            record.setShopId(shopId);
            record.setUid(uid);
            this.save(record);
        });
    }


    @Transactional
    public int deleteAll(long uid) {
        return ResUtils.getDefault(this.repository.deleteByUid(uid));
    }

    @Transactional
    public int deleteByUid(long uid, Long[] id) {
        return ResUtils.getDefault(this.repository.deleteByUid(uid,id));
    }
}
